package com.masterclient.app.modules.search.adapter;

import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.masterclient.app.R;
import com.masterclient.app.modules.search.SearchShopMessage;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.baselibrary.utils.ViewTransformUtil;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

/**
 * 作者：sean
 * 创建时间：2017/6/25 12:16
 * 功能说明：
 */

public class SearchShopRecyclerAdapter extends BaseQuickAdapter<SearchShopMessage, BaseViewHolder> {

//    @BindView(R.id.iv_brand_logo)
//    ImageView ivBrandLogo;
//    @BindView(R.id.tv_brand_name)
//    TextView tvBrandName;
//    @BindView(R.id.tv_location)
//    TextView tvLocation;
//    @BindView(R.id.tv_brand_desc)
//    TextView tvBrandDesc;

    public SearchShopRecyclerAdapter() {
        super(R.layout.item_search_shop);
    }

    @Override
    protected void convert(BaseViewHolder helper, SearchShopMessage item) {


        ViewTransformUtil.glideImageView(mContext,item.getSh_logo(),(ImageView) helper.getView(R.id.iv_brand_logo),
                new RoundedCornersTransformation(ScreenUtils.dp2px(7),0),R.mipmap.defaults);
        helper.setText(R.id.tv_brand_name,item.getSh_store_name());
        helper.setText(R.id.tv_brand_desc,item.getSh_business_scope());
        helper.setVisible(R.id.search_shop_line,helper.getAdapterPosition() != getData().size()-1);
        LinearLayout storeTagRecommendll = helper.getView(R.id.ll_store_tag);
        ImageView storeTagRecommendicon = helper.getView(R.id.iv_store_tag);
        TextView storeTagRecommend = helper.getView(R.id.tv_store_tag);
        if (item.getSh_shop_icon() != null && !TextUtils.isEmpty(item.getSh_shop_icon().getBg_header_color())) {
            storeTagRecommendll.setVisibility(View.VISIBLE);
            int[] colors = {Color.parseColor(item.getSh_shop_icon().getBg_header_color()),
                    Color.parseColor(item.getSh_shop_icon().getBg_footer_color())};
            GradientDrawable drawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colors);
            drawable.setCornerRadius(ScreenUtils.dp2px(2));
            drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
            storeTagRecommendll.setBackground(drawable);
            storeTagRecommend.setText(item.getSh_shop_icon().getTitle());
            ViewTransformUtil.glideImageView(mContext, item.getSh_shop_icon().getPre_icon(), storeTagRecommendicon,
                    new Transformation[]{new CenterCrop()}, R.mipmap.defaults_1);
        }else {
            storeTagRecommendll.setVisibility(View.GONE);
        }


    }
}
